package com.example.jf.jfapp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.jf.jfapp.R;
import com.example.jf.jfapp.bean.response.BlogCommentResponse;
import com.example.jf.jfapp.widget.GlideCircleTransform;

import java.util.ArrayList;

/**
 * Created by jf on 2017/7/28.
 */

public class BlogCommentAdapter extends RecyclerView.Adapter<BlogCommentAdapter.ItemViewHolder> {

    private BlogCommentResponse mBlogCommentResponse;
    ArrayList<BlogCommentResponse.ResultBean> mResultBean=new ArrayList<>();

    private Context mContext;



    public BlogCommentAdapter(Context context, ArrayList<BlogCommentResponse.ResultBean> mResultBean) {
        this.mResultBean = mResultBean;
        this.mContext = context;
    }

    @Override
    public BlogCommentAdapter.ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false);
        ItemViewHolder itemViewHolder = new ItemViewHolder(view);
        return itemViewHolder;
    }

    @Override
    public void onBindViewHolder(final BlogCommentAdapter.ItemViewHolder holder, final int position) {
        BlogCommentResponse.ResultBean bean = mResultBean.get(position);
        holder.tv_name.setText(bean.getAuthor().getUsername());

        Glide.with(holder.itemView.getContext())
                .load(bean.getAuthor().getHeadProtrait())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new GlideCircleTransform(holder.itemView.getContext()))
                .into(holder.iv_head);


        holder.tv_date.setText(bean.getContent());

    }


    @Override
    public int getItemCount() {
       // return mBlogCommentResponse.getResult().size();
        return mResultBean.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_head;
        TextView tv_name;
        TextView tv_date;

        public ItemViewHolder(View itemView) {
            super(itemView);
            iv_head = itemView.findViewById(R.id.iv_head);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_date = itemView.findViewById(R.id.tv_date);
        }
    }

}
